<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>图书管理</title>
    <%@ include file="/pages/common/head.jsp" %>
    <script type="text/javascript">
        $(function () {
            $("a.delete").click(function () {
                let bookName = $(this).parent().parent().find("td.name").text();
                return confirm(`确认要删除《` + bookName + `》吗？`);
            });

            $("#goto").click(function () {
                let pnT = $("#pn_input").val();
                if (pnT >= 1 && pnT <= ${page.pt}) {
                    location.href = "${page.urlAction}&pn=" + pnT;
                } else {
                    alert("请输入正确的页码！");
                }
                return false;
            });
        });
    </script>
</head>
<body>

<div id="header">
    <img class="logo_img" alt="" src="static/img/logo.gif">
    <span class="wel_word">图书管理系统</span>
    <%@ include file="/pages/common/manager_menu.jsp" %>
</div>

<div id="main">
    <table>
        <tr>
            <td>名称</td>
            <td>价格</td>
            <td>作者</td>
            <td>销量</td>
            <td>库存</td>
            <td colspan="2">操作</td>
        </tr>
        <c:forEach items="${page.pes}" var="book">
            <tr>
                <td class="name">${book.name}</td>
                <td class="price">${book.price}</td>
                <td class="author">${book.author}</td>
                <td class="sales">${book.sales}</td>
                <td class="stock">${book.stock}</td>
                <td class="edit"><a href="${page.url}?action=queryBook&id=${book.id}&method=updateById&pn=${page.pn}">修改</a>
                </td>
                <td class="delete"><a class="delete" href="${page.urlAction}?action=delete&id=${book.id}&pn=${page.pn}">删除</a></td>
            </tr>
        </c:forEach>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td><a href="pages/manager/book_edit.jsp?method=add&pn=${page.pt}">添加图书</a></td>
        </tr>
    </table>

    <%@ include file="/pages/common/page_nav.jsp" %>
</div>

<%@ include file="/pages/common/footer.jsp" %>
</body>
</html>